package com.niannian.adapter;

import java.util.ArrayList;
import com.niannian.R;
import com.niannian.bean.SystemNewsBean;
import com.niannian.db.MyDBUser;
import com.niannian.util.Common;
import com.niannian.util.UserInfoManager;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 系统消息适配器
 * 
 * @author shenglin
 * 
 */
public class SystemNewsAdaper extends BaseAdapter {
	protected MyDBUser userInfoManager = UserInfoManager.getUserInfoInstance();
	private ArrayList<SystemNewsBean> ndatas;
	private LayoutInflater inflater;
	private Activity mActivity;
	BaseAdapter adapter;

	public SystemNewsAdaper(Activity activity) {
		super();
		this.mActivity = activity;
		inflater = LayoutInflater.from(mActivity);
		this.ndatas = new ArrayList<SystemNewsBean>();
	}

	@Override
	public int getCount() {
		return ndatas.size();
	}

	@Override
	public Object getItem(int arg0) {
		return ndatas.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	public ArrayList<SystemNewsBean> getDatasList() {
		return ndatas;
	}

	public void setAdapter(BaseAdapter adapter) {
		this.adapter = adapter;
	}

	@Override
	public View getView(final int position, View v, ViewGroup arg2) {
		ViewHolder holder = null;
		if (v == null) {
			v = inflater.inflate(R.layout.item_system_news, null);
			holder = new ViewHolder();
			holder.ll_system_news = (LinearLayout) v.findViewById(R.id.ll_system_news);

			holder.tv_title = (TextView) v.findViewById(R.id.tv_title);
			holder.tv_time = (TextView) v.findViewById(R.id.tv_time);
			holder.tv_info = (TextView) v.findViewById(R.id.tv_info);

			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		final SystemNewsBean Ndata = ndatas.get(position);
		holder.tv_title.setText(Ndata.getTitle());
		holder.tv_time.setText(Common.sgmdate(Ndata.getCreated_time()));
		holder.tv_info.setText(Ndata.getDesc());

		holder.ll_system_news.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
			}
		});

		return v;
	}

	class ViewHolder {
		LinearLayout ll_system_news;

		TextView tv_title;
		TextView tv_time;
		TextView tv_info;

	}

}
